package gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.Color;

import javax.swing.border.LineBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;

import classes_basicas.Cliente;
import classes_basicas.Endereco;
import classes_basicas.Funcionario;
import fachada.Fachada;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.DefaultComboBoxModel;

public class Cad_Funcionario {

	 JFrame frame;
	private JTextField txbnome;
	private JTextField txbcpf;
	private JTextField txbtelefone;
	private JTextField txblogradouro;
	private JTextField txbbairro;
	private JTextField txbcidade;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Cad_Funcionario window = new Cad_Funcionario();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Cad_Funcionario() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 428, 475);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new LineBorder(new Color(128, 0, 0), 2));
		panel.setBackground(new Color(135, 206, 250));
		panel.setBounds(0, 0, 421, 445);
		frame.getContentPane().add(panel);
		
		JLabel lblCadastroDeFuncionrios = new JLabel("Cadastro de Funcion\u00E1rios");
		lblCadastroDeFuncionrios.setForeground(new Color(128, 0, 0));
		lblCadastroDeFuncionrios.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblCadastroDeFuncionrios.setBounds(97, 42, 235, 25);
		panel.add(lblCadastroDeFuncionrios);
		
		JLabel label_1 = new JLabel("Nome:");
		label_1.setBounds(59, 107, 46, 14);
		panel.add(label_1);
		
		JLabel label_2 = new JLabel("Cpf:");
		label_2.setBounds(59, 132, 46, 14);
		panel.add(label_2);
		
		JLabel label_3 = new JLabel("Sexo:");
		label_3.setBounds(59, 157, 46, 14);
		panel.add(label_3);
		
		JLabel label_4 = new JLabel("Telefone:");
		label_4.setBounds(59, 183, 62, 14);
		panel.add(label_4);
		
		txbnome = new JTextField();
		txbnome.setColumns(10);
		txbnome.setBounds(97, 104, 246, 20);
		panel.add(txbnome);
		
		txbcpf = new JTextField();
		txbcpf.setColumns(10);
		txbcpf.setBounds(97, 132, 246, 20);
		panel.add(txbcpf);
		
		txbtelefone = new JTextField();
		txbtelefone.setColumns(10);
		txbtelefone.setBounds(118, 180, 225, 20);
		panel.add(txbtelefone);
		
		final JComboBox combosexo = new JComboBox();
		combosexo.setModel(new DefaultComboBoxModel(new String[] {"Selecione o sexo:", "Masculino", "Feminino"}));
		combosexo.setBounds(97, 157, 144, 20);
		panel.add(combosexo);
		
		JLabel label_5 = new JLabel("Logradouro:");
		label_5.setBounds(59, 208, 73, 14);
		panel.add(label_5);
		
		txblogradouro = new JTextField();
		txblogradouro.setColumns(10);
		txblogradouro.setBounds(128, 205, 215, 20);
		panel.add(txblogradouro);
		
		JLabel label_6 = new JLabel("Bairro:");
		label_6.setBounds(59, 234, 62, 14);
		panel.add(label_6);
		
		txbbairro = new JTextField();
		txbbairro.setColumns(10);
		txbbairro.setBounds(97, 231, 246, 20);
		panel.add(txbbairro);
		
		JLabel label_7 = new JLabel("Cidade:");
		label_7.setBounds(59, 262, 62, 14);
		panel.add(label_7);
		
		txbcidade = new JTextField();
		txbcidade.setColumns(10);
		txbcidade.setBounds(118, 259, 225, 20);
		panel.add(txbcidade);
		
		JLabel label_8 = new JLabel("Estado:");
		label_8.setBounds(59, 290, 62, 14);
		panel.add(label_8);
		
		final JComboBox comboestado = new JComboBox();
		comboestado.setModel(new DefaultComboBoxModel(new String[] {"Selecione o estado:", "Acre ", "Alagoas ", "Amap\u00E1 ", "Amazonas ", "Bahia  ", "Cear\u00E1 ", "Distrito Federal  ", "Esp\u00EDrito Santo ", "Goi\u00E1s", "Maranh\u00E3o ", "Mato Grosso ", "Mato Grosso do Sul ", "Minas Gerais ", "Par\u00E1 ", "Para\u00EDba ", "Paran\u00E1 ", "Pernambuco ", "Piau\u00ED ", "Rio de Janeiro ", "Rio Grande do Norte ", "Rio Grande do Sul ", "Rond\u00F4nia ", "Roraima ", "Santa Catarina ", "S\u00E3o Paulo ", "Sergipe ", "Tocantins "}));
		comboestado.setBounds(112, 287, 144, 20);
		panel.add(comboestado);
		
		JButton button = new JButton("Salvar");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Funcionario f = new Funcionario();
				Endereco e  =new Endereco();
				try {
					f.setNome(txbnome.getText());
					f.setCpf(txbcpf.getText());
					f.setSexo((String) combosexo.getSelectedItem());
					f.setTelefone(txbtelefone.getText());
					e.setLogradouro(txblogradouro.getText());
					e.setBairro(txbbairro.getText());
					e.setCidade(txbcidade.getText());
					e.setEstado((String) comboestado.getSelectedItem());
					f.setEndereco(e);
					
					Fachada fc = new Fachada();
					
						fc.inserirfuncionario(f);
						JOptionPane.showMessageDialog(null,"Cadastrado com Sucesso!");
					
				} catch (Exception e1) {
					JOptionPane.showMessageDialog(null,e1.getMessage());
				}
			}
		});
		button.setBounds(122, 340, 90, 28);
		panel.add(button);
		
		JButton button_1 = new JButton("Voltar");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setVisible(false);
				Menu m = new Menu();
				m.frame.show();
			}
		});
		button_1.setBounds(224, 340, 90, 28);
		panel.add(button_1);
	}
}
